package cn.pugle.base.classloader;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;

/**
 * -XX:MaxMetaspaceSize=1m 不加就不爆炸哦, 本机内存不爆它不爆
 * "元空间'并不在虚拟机中'，而是使用本地内存。因此，默认情况下，元空间的大小仅受本地内存限制"
 *
 * @author tzp
 * @since 2020/11/14
 */
public class OOMTest1 {
    public static void main(String[] args) {
        URL url = null;
        List<ClassLoader> classLoaderList = new ArrayList<ClassLoader>();
        try {
            url = new File("/Users/tzp/Documents/private/cnm/CodeAccumulate/javasrc/target/classes").toURI().toURL();
            URL[] urls = {url};
            while (true) {
                ClassLoader loader = new URLClassLoader(urls);
                classLoaderList.add(loader);
                loader.loadClass("cn.pugle.base.classloader.AClass");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
